<%@ page import="com.example.mystore.entity.Commodity" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>购物车</title>
    <link rel="stylesheet" href="css/header.css">
    <link rel="stylesheet" href="css/footer.css">
    <style>
        .banner {width: 1000px;height: 600px;border: 1px solid darkorange;margin: auto}
        .banner .bannerHeader { width: 1000px;height: 60px;margin-top: 20px}
        .banner .bannerHeader .title { font-size: 25px;margin-left: 40px;}
        .banner .bannerMain { width: 950px;height: 420px;margin: 20px auto;text-align: center; overflow: scroll}
        .banner .bannerMain::-webkit-scrollbar {display:none}
        .banner .bannerMain .order{background-color:#bdb9b9;border: 1px solid white}
        .banner .bannerMain .order:hover{background-color: #8799a3;}
        .banner .bannerMain .order td{padding: 0;}
        .banner .bannerMain .order td input{width: 50%;}
        .banner .bannerFooter { width: 950px;height: 50px;margin: auto;position: relative}
        .banner .bannerFooter .update { width: 100px;height: 40px}
        .banner .bannerFooter .pay { width: 100px;height: 40px;right: 10px;position: absolute}
        .banner .bannerFooter input { background-color: #fc5531;border: white;color: white;border-radius: 20px;cursor: pointer}
        .banner .bannerFooter .countInfo { width: 700px;text-align: right;display: inline-block}
        .banner .bannerFooter .countPrice { font-size: 30px;color: #fc5531}
    </style>
</head>
<body>
<header id="header">
    <div id="headerBox">
        <h1>品优购</h1>
        <a href="display.jsp">返回首页</a>
        <a href="">联系客服</a>
        <a href="${pageContext.request.contextPath}/LogoutServlet" style="float: right">退出登录</a>
        <hr>
    </div>
</header>
<div class="banner">
    <div class="bannerHeader">
        <span class="title">我的购物车</span>
        <hr style="width: 950px;margin: 10px auto;border: 1px solid darkorange">
    </div>
    <div class="bannerMain">
        <table style="border-collapse:collapse;">
            <tr>
                <th width="110px">产品ID</th>
                <th width="400px">产品名称</th>
                <th width="110px">数量</th>
                <th width="110px">单价</th>
                <th width="110px">小计</th>
                <th width="110px">移去</th>
            </tr>
            <%  int countNumb = 0;
                double countPrice = 0.00;
                HashMap<Commodity,Integer> cart = (HashMap<Commodity, Integer>) request.getSession().getAttribute("cart");
            if(cart != null){%>
            <%for (Map.Entry<Commodity,Integer> entry: cart.entrySet()){%>
            <%countNumb += entry.getValue();
            countPrice += entry.getKey().getPrice()*entry.getValue();%>
            <tr class="order">
                <td width="110px" style="text-align: center"><%=entry.getKey().getId()%></td>
                <td width="400px"><%=entry.getKey().getName()%></td>
                <td width="110px" style="text-align: center">
                    <a href="${pageContext.request.contextPath}/toAdd?id=<%=entry.getKey().getId()%>"><input type="button" value="+"></a>
                    <input type="number"value="<%=entry.getValue()%>" max="999" min="1" readonly>
                    <a href="${pageContext.request.contextPath}/toReduce?id=<%=entry.getKey().getId()%>"><input type="button" value="-"></a>
                </td>
                <td width="110px" style="text-align: center"><%=entry.getKey().getPrice()%></td>
                <td width="110px" style="text-align: center"><%=new DecimalFormat("#0.00").format(entry.getKey().getPrice()*entry.getValue())%></td>
                <td width="110px" style="text-align: center"><a href="${pageContext.request.contextPath}/toDel?id=<%=entry.getKey().getId()%>"><input type="button" value="删除"></a></td>
            </tr>
            <%}
            }%>
        </table>
    </div>
    <div class="bannerFooter">
        <a href="${pageContext.request.contextPath}/toClear">
            <input type="submit"value="清空购物车"class="update">
        </a>
            <div class="countInfo">
                <span>已选择<b><%=countNumb%></b>件商品</span>
                <span>合计为<span class="countPrice">￥<%=new DecimalFormat("#0.00").format(countPrice)%></span></span>
            </div>
        <a href="${pageContext.request.contextPath}/Settlement?FinalPrice=<%=new DecimalFormat("#0.00").format(countPrice+(countPrice/1000)+(countNumb*5))%>">
            <input type="button" class="pay"value="结算">
        </a>
    </div>
</div>
<footer id="footer">
    <div id="footerBox">
        <div class="">
            <a  href="">
                关于我们
            </a>
            |
            <a href="">
                联系我们
            </a>
            |
            <a href="">
                人才招聘
            </a>
            |
            <a  href="">
                商家入驻
            </a>
            |
            <a href="">
                广告服务
            </a>
            |
            <a  href="">
                友情链接
            </a>
            |
            <a  href="">
                销售联盟
            </a>
            |
            <a href="" >
                商家社区
            </a>
            |
            <a href="" >
                捐款公益
            </a>
        </div>
        <div class="">
            1107841498@qqcom&nbsp;©&nbsp;&nbsp;&nbsp;&nbsp;版权归<a href="">@清秋</a>所有
        </div>
    </div>
    </footer>
</body>
</html>
